/* window.onload = function() {
	init();
	document.getElementsByName("tema")[0].onchange = changeTheme;
	document.getElementById("content-like-1").innerHTML = l1;
	document.getElementById("content-like-2").innerHTML = l2;
	document.getElementById("content-like-3").innerHTML = l3;
	document.getElementById("content-like-4").innerHTML = l4;
	document.getElementById("content-like-5").innerHTML = l5;
	document.getElementById("content-like-6").innerHTML = l6;
	document.getElementById("content-like-7").innerHTML = l7;
	document.getElementById("content-like-8").innerHTML = l8;
	document.getElementById("content-like-9").innerHTML = l9;
	document.getElementById("content-like-10").innerHTML = l10;
}
 */
//with possibility of negative numbers
function generateRandomLikes(upperlimit) {
	var ret = Math.floor(Math.random()*(upperlimit + 1));
	if(Math.floor(Math.random()*2) == 0) {
		ret *= -1;
	}
	return ret;
}


function changeTheme() {
	var tema = document.getElementsByName("tema")[0];
	if(tema.options[tema.selectedIndex].value == "klasik") {
		var cssfile = document.getElementById("cssfile");
		cssfile.setAttribute("href","style1.css");
	} else if(tema.options[tema.selectedIndex].value == "pelangi"){
		var cssfile = document.getElementById("cssfile");
		cssfile.setAttribute("href","style2.css");
	}
}

function doLikeOp(_op,identifier)
{
	var xmlhttp;	
	//lolos validasi
	if (window.XMLHttpRequest){
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {		
			//cek apakah error 
			var temp_op = _op.split(/@/);
			var temp = xmlhttp.responseText.split(/[\s]+/);			
			var cont = document.getElementById('content-like-'+temp_op[1]);
			var cont2= document.getElementsByClassName('content-like-'+temp_op[1]);
			var i=0;
			if(temp[0] !="error") {			
				//berhasil
				/* alert (identifier); */
				if(identifier == "id")
					cont.innerHTML=xmlhttp.responseText;
				else
				{
					for(i=0;i<cont2.length;i++)
						cont2[i].innerHTML = xmlhttp.responseText;
				}
				/* alert(xmlhttp.responseText); */
			}
			else
			{
				temp_str = xmlhttp.responseText.substring(temp[0].length);
				if(!temp_str==0)
					alert(temp_str);			
			}

		}
	}

	xmlhttp.open("POST","ajax/list_response.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("operation="+_op);
}

function dynamicScroll(last,tag,filtermode,sortmode,maxinpage,maxheight)
{
		var xmlhttp;	
		var max = document.documentElement.scrollHeight - document.documentElement.clientHeight;
		maxheight= new maxHeight(max);
		var permittoquery = false;
	//lolos validasi
	if (window.XMLHttpRequest){
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function() {
		_op= "scroll";
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {	
			var winYOffset = window.pageYOffset;
			var cont = document.getElementsByClassName('contentcontainer')[0];
			var temp = xmlhttp.responseText.split(/[\s]+/);	
			var i=0;

			if(temp[0] !="error" && temp[0]=="plus") {			
				incrementObjectVal(last,maxinpage);
				var response_temp = xmlhttp.responseText.substr(4);
				cont.innerHTML = cont.innerHTML + response_temp;

			}
		}
	}

	xmlhttp.open("POST","ajax/list_response.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("operation=scroll@"+window.pageYOffset+"&&last="+last.value+"&&tag="+tag+"&&filtermode="+filtermode+"&&sortmode="+sortmode+"&&maxyscroll="+maxheight.value+"&&permission="+permittoquery);
}

function setBodyDynamicScroll(last,tag,filtermode,sortmode,maxinpage,maxheight)
{
	 window.onscroll = function(){dynamicScroll(last,tag,filtermode,sortmode,maxinpage,maxheight);}
}
function incrementObjectVal(obj,inc)
{
	obj.value += inc;
}
function setObjectVal(obj,val)
{
	obj.value = val;
}
function maxHeight(val)
{
	this.value=val;
}
